/*
 * Misc Utilities.
 * $Rev: 163 $
 */

#ifndef __UTILS_H
#define __UTILS_H

#include <stdbool.h>   // bool

#ifdef __DEBUG
#include <stdio.h>
#define debug(s,...) printf(s, ##__VA_ARGS__)
#else
#define debug(s,...)
#endif

#define DIR_SEPARATOR "/"

/*
 * PRE: `a_path' is a valid path name
 * POST: returns true if `a_path' points to a regular file
 */
bool path_is_file(const char *a_path);

/*
 * PRE: `a_path' is a valid path name
 * POST: returns true if `a_path' points to a directory
 */
bool path_is_directory(const char *a_path);

/*
 * PRE: `a_path' is a valid file path name
 * POST: returns the size in bytes of `a_path'
 */
off_t path_size(const char *a_path);

/*
 * PRE: true
 * POST: returns true if `a_path' is a valid path name
 */
bool valid_path_name(const char *a_path);

/*
 * PRE: `p' and `q' are valid path names
 * POST: returns a newly allocated string (terminated in '\0')
 *       which is the concatenation of p + DIR_SEPARATOR + q
 * NOTE: the returned string MUST BE FREED
 *       by the calling process. Otherwise mem leaks are ensured.
 */
char *path_join(const char *p, const char *q);

#endif /* __UTILS_H */
